package com.chixing.day10_hashcode_exception.word;

import java.util.Arrays;

public class Company {
    private int companyId;
    private String companyName;
    private String companyType;
    private String companyTag;





    public Company(){

    }
    public Company(int companyId, String companyName, String companyType, String companyTag) {
        this.companyId = companyId;
        this.companyName = companyName;
        this.companyType = companyType;
        this.companyTag = companyTag;
    }

    public int getCompanyId() {
        return companyId;
    }

    public void setCompanyId(int companyId) {
        this.companyId = companyId;
    }

    public String getCompanyName() {
        return companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    public String getCompanyType() {
        return companyType;
    }

    public void setCompanyType(String companyType) {
        this.companyType = companyType;
    }

    public String getCompanyTag() {
        return companyTag;
    }

    public void setCompanyTag(String companyTag) {
        this.companyTag = companyTag;
    }

    @Override
    public String toString() {
        return "Company{" +
                "companyId=" + companyId +
                ", companyName='" + companyName + '\'' +
                ", companyType='" + companyType + '\'' +
                ", companyTag='" + companyTag + '\'' +
                '}';
    }

    //发布职位
    private  int count = 0;

    private Position[] positions = new Position[5];
    public void publishPosition(Position position){
        for (int i=0;i<=5;i++){
            if (count==0){
                positions[count]=position;
                break;
            }else if (this.companyId==position.getCompany().getCompanyId()&& positions[i].getPsoName()!=position.getPsoName()){
                positions[count] = position;
                break;
            }else if (this.companyId!=position.getCompany().getCompanyId())
                return;
        }
        count++;
        System.out.println(Arrays.toString(positions));
    }

    //统计每个公司个个地区岗位发布数量

    public void selectCitynum(){
        int com1 = 0;
        String cityTemp ="";
        for (int i = 0; i < count; i++) {
            if (positions[i].getCompany().getCompanyName() == this.getCompanyName()){
                cityTemp += positions[i].getPosCity() + " ";
                com1++;
            }
        }
        System.out.println(this.companyName+"：");
        String[] cityT = cityTemp.split(" ");
        for (int t = 0; t < cityT.length; t++) {
            int connt = 0;
            int num = 0;
            if (cityT.length==1) {System.out.println("该公司没有发布岗位");return;}
            if (!cityTemp.substring(0, t+1).contains(cityT[t])) {
                while (cityTemp.indexOf(cityT[t], connt) != -1) {
                    connt = cityTemp.indexOf(cityT[t], connt) + 1;
                    num++;
                }
                System.out.println(cityT[t] + "的发布数量:" + num);
            }
        }
    }


    public void getCount(){
        int sum = 0;
        for (int i=0;i<count;i++){
            if (positions[i].getCompany().companyName==this.companyName){
                sum++;
            }
        }
        System.out.println(this.companyName+"公司发布"+sum+"个岗位");
    }

    //查询出"计算机"类的公司 招聘的岗位，存储到数组中
    private static int num = 0;
    private static Position[] computer = new Position[5];

    public void pushComputer(Position position){
        for (int i=0;i<num+1;i++){
            if (this.companyTag.contains("计算机")){
                if (num==0){
                    computer[num] = position;
                    break;
                }else {
                    computer[num] = position;
                    break;
                }
            } else  {
                return;
            }
        }
        num++;
        System.out.println(Arrays.toString(computer));

    }

}
